package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.mapper.DeliveryItemMapper;
import com.rongke.model.DeliveryItem;
import com.rongke.service.DeliveryItemService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * @DeliveryItemController
 * @配送方案子选项Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/deliveryItem")
@Transactional
@CrossOrigin
public class DeliveryItemController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private DeliveryItemService deliveryItemService;

    /**
     * @添加配送方案子选项
     * @param deliveryItem
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addDeliveryItem(@RequestBody DeliveryItem deliveryItem){
        log.debug("添加配送方案子选项");
        deliveryItemService.insert(deliveryItem);
        return JsonResp.ok(deliveryItem);
    }

    /**
     * @修改配送方案子选项
     * @param deliveryItem
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateDeliveryItem(@RequestBody DeliveryItem deliveryItem){
        log.debug("修改配送方案子选项");
        deliveryItemService.updateById(deliveryItem);
        return JsonResp.ok(deliveryItem);
    }
    /**
     * @根据id查找配送方案子选项
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectDeliveryItem(Long id){
        log.debug("查找配送方案子选项");
        DeliveryItem deliveryItem = deliveryItemService.selectById(id);
        return JsonResp.ok(deliveryItem);
    }

    /**
     * @根据条件查找配送方案子选项
     * @param deliveryItem
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectDeliveryItemByCondition(@RequestBody DeliveryItem deliveryItem){
        log.debug("根据条件查找配送方案子选项");
        if(deliveryItem==null)
            return JsonResp.toFail("参数不能为空");
        List<DeliveryItem> deliveryItemList=deliveryItemService.selectByCondition(deliveryItem);
        return JsonResp.ok(deliveryItemList);
    }

}
